(function(window){
	window.gameOver=gameOver;
	function gameOver(options){
		this.ctx=options.ctx;
		
		//
		
	}
	util.extend(gameOver.prototype, {
		// 绘制游戏结束场景
		run:function(){
			this.ctx.save();
			this.ctx.beginPath();
			
			//结束场景的x，y轴坐标
			this.x=this.ctx.canvas.width;
			this.y=this.ctx.canvas.height;
			
			//绘制游戏结束矩形
			this.ctx.fillStyle="rgba(0,0,0,0.5)";
			this.ctx.rect(0,0,this.x,this.y);
			this.ctx.fill();
			
			//绘制游戏结束的文字
			this.ctx.font="900 60px 微软雅黑";
			this.ctx.textAlign="center";
			this.ctx.textBaseline="bottom";
			this.ctx.fillStyle="orange";
			this.ctx.fillText("GAMEOVER!!!",this.x/2,this.y/2-30);
			
			this.makeBtn();
			this.ctx.restore();
		},
		//绘制重新开始按钮
		makeBtn:function(){
			//绘制小矩形
			this.ctx.beginPath();
			this.ctx.strokeStyle="deeppink";
			this.ctx.lineWidth=6;
			this.btnWidth=300;
			this.btnHeight=100;
			this.btnX=this.x/2-this.btnWidth/2;
			this.btnY=this.y/2-this.btnHeight/2+40;
			this.ctx.rect(this.btnX,this.btnY,this.btnWidth,this.btnHeight);
			this.ctx.stroke();
			
			//绘制文字
			this.ctx.beginPath();
			this.ctx.font="900 40px 微软雅黑";
			this.ctx.textAlign="center";
			this.ctx.baseline="center";
			this.ctx.fillStyle="deeppink";
			this.ctx.fillText("游戏重新开始",this.x/2,this.y/2+60);
			
			this.bind();
		},
		//绑定点击事件
		bind:function(){
			var self=this;
			this.ctx.canvas.addEventListener("click",function(e){
				var pointX=e.pageX-this.offsetLeft;
				var pointY=e.pageY-this.offsetTop;
				//画按钮的矩形路径
				self.ctx.beginPath();
				self.ctx.rect(self.btnX,self.btnY,self.btnWidth,self.btnHeight);
				
				//如果点击按钮所在路线，则重新记载页面
				if( self.ctx.isPointInPath(pointX,pointY)){
					location.reload();
				}
			})
		}
		
	})
}(window))
